var Log = require('../framework/log');
function PlayerManager(app){
    this.app = app;
    this.players = {};
};

PlayerManager.prototype.addPlayer = function(player){
    this.players[player.id] = player;
};

PlayerManager.prototype.delPlayer = function(id){
    delete this.players[id];
};

PlayerManager.prototype.hasPlayer = function(id){
    return this.players.hasOwnProperty(id);
};

PlayerManager.prototype.getPlayer = function(id){
    return this.players[id];
}

PlayerManager.prototype.getAllPlayerId = function(){
    var ret = [];
    for(var k in this.players){
        if(this.players.hasOwnProperty(k)){
            ret.push(k);
        }
    }
    return ret;
};

//notify all player
PlayerManager.prototype.notifyAll = function(msg){
    for(var k in this.players){
        if(this.players.hasOwnProperty(k)){
            var player = this.players[k];
            player.getSession().notify(msg);
        }
    }
};

module.exports = PlayerManager;